package hacker_rank.oct13;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ChocolateFeast {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int T = Integer.parseInt(br.readLine());

		for (int t = 1; t <= T; t++) {
			String line = br.readLine();
			String[] tmp = line.split(" ");
			int N = Integer.parseInt(tmp[0]);
			int C = Integer.parseInt(tmp[1]);
			int M = Integer.parseInt(tmp[2]);
			solve(N, C, M);
		}
	}

	private static void solve(int N, int C, int M) {
		int t = N / C;
		int res = 0;

		res = t + f(t, M);
		System.out.println(res);

	}

	private static int f(int t, int m) {
		if (t < m)
			return 0;

		return (t / m) + f(t / m + (t % m), m);
	}

}
